fn change(mut x: i32) -> i32{
    x + 4
}

fn modify_i32(x:& mut i32) {
    *x += 10
}

pub fn study() {
    // match_study();
    // loop_study();
    let mut x = 50;
    modify_i32(&mut x); // 引用传递

    let y = change(x);
    println!("x: {}", x);
    println!("y: {:?}", y);
}

//  match学习
fn match_study() {
    let num = 30;

    // 精准匹配与范围匹配
    match num {
        25 ..=50 => println!("num: {}", num),
        51 ..=100 => println!("num: {}", num),
        _ => println!("无匹配")
    }

    // 或匹配
    match num {
        10 | 20 | 30 => println!("10 | 20 | 30"),
        40 | 50 | 60 => println!("40 | 50 | 60"),
        _ => println!("some else"),
    }

    // if
    match num {
        x if x < 60 => {
            println!("小于60");
        }
        x if x > 60 => {
            println!("大于60");
        }
        _ => println!("some else")
    }
}

// 循环学习
fn loop_study() {
    let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
    for i in arr {
        println!("i: {}", i);
    }

    'outer: loop {
        println!("outer");
        loop {
            print!("inner");
            break 'outer;
        }
    }

    // 迭代写法
    let arr1 = [2, 4, 1, 5, 7].to_vec();
    let iter_number: Vec<_> = arr1.iter().map(|&x| x * x).collect();
    println!("iter_number: {:?}", iter_number);
}
